package com.laikan.reader.core.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.laikan.library.utils.SPUtil;
import com.laikan.reader.core.LaikanBaseAdapter;
import com.laikan.reader.R;
import com.laikan.reader.core.bean.MessageBean;

import java.util.ArrayList;

public class MessageAdapter extends LaikanBaseAdapter<MessageBean> {

    public MessageAdapter(Context context, ArrayList<MessageBean> datas) {
        super(context, datas);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup arg2) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(mContext, R.layout.lk_message_item, null);
            holder.person_img = (ImageView)convertView.findViewById(R.id.head_reviewer_img);
            holder.message_title = (TextView)convertView.findViewById(R.id.message_title);
            holder.message_content = (TextView)convertView.findViewById(R.id.message_content);
            holder.message_time = (TextView)convertView.findViewById(R.id.message_time);
            holder.message_new = (ImageView)convertView.findViewById(R.id.message_new);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder)convertView.getTag();
        }
        if (!SPUtil.getBoolean("message_" + datas.get(position).getId(), false)) {
            holder.message_new.setVisibility(View.VISIBLE);
        }else {
            holder.message_new.setVisibility(View.GONE);
        }
        holder.message_title.setText(datas.get(position).getTitle());
        holder.message_content.setText(datas.get(position).getContent());
        holder.message_time.setText(datas.get(position).getCreateTime());
        holder.person_img.setImageURI(Uri.parse(datas.get(position).getIcon()));
        return convertView;
    }

    private class ViewHolder {

        private ImageView person_img;
        private TextView message_title, message_content, message_time;
        private ImageView message_new;
    }

}
